﻿using System;
namespace Validate.Net
{
    /// <summary>
    /// 校验字符串最小长度
    /// </summary>
    public class ValidateMinLengthAttribute : AbstractValidateAttribute
    {
        private int minLeng;

        public ValidateMinLengthAttribute(int minLeng)
        {
            this.minLeng = minLeng;
        }

        public override bool Validate(object value, out string msg)
        {
            if (value != null && value.ToString().Trim().Length >= this.minLeng)
            {
                msg = string.Empty;
                return true;
            }
            else
            {
                msg = $"最小长度为：{this.minLeng}";
                return false;
            }
        }
    }
}
